package com.sunday.fangdaifu.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

/**
 * Created by 刘涛 on 2017/7/5.
 */

public class PieChart extends View {

    private float mOutRadius=dp2px(120);
    private float mIntRadius=dp2px(100);
    private int mOutStrokeWidth=dp2px(8);
    private int mIntStrokeWidth=dp2px(10);
    private Paint paint;
    private float firsrChildAngle;


    public PieChart(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init(){
        paint=new Paint();
        paint.setColor(Color.GRAY);
        paint.setAntiAlias(true);
        paint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if (widthMode != MeasureSpec.EXACTLY) {
            int widthSize = (int) (mOutRadius * 2);
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
        }
        if (heightMode != MeasureSpec.EXACTLY) {
            int heightSize = (int) (mOutRadius * 2);
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private float xy;//圆心坐标

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        xy = getWidth() / 2;
        RectF rectF = new RectF(0, 0, mOutRadius * 2, mOutRadius * 2);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setColor(Color.GRAY);
        paint.setStrokeWidth(mOutStrokeWidth);
        canvas.drawCircle(xy, xy, mOutRadius, paint);

        RectF rectF1=new RectF(0,0,mIntRadius*2,mIntRadius*2);
        drawArc(canvas,rectF1);

    }

    private void drawArc(Canvas canvas,RectF rectF){


    }

    /**
     * dp 2 px
     *
     * @param dpVal
     */
    protected int dp2px(int dpVal) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                dpVal, getResources().getDisplayMetrics());
    }

}
